import {BaseController, BeanFactory, Controller, PostMapping, Result,Resource} from "csap-typescript-vue2/lib";
import {UserService} from "@/api/service/UserService";
import {UserModel} from "@/api/model/user/UserModel";
import {AxiosPromise} from "axios";

/**
 * 用户
 */
@Controller("apiDocUser")
export class UserController extends BaseController<UserService, UserModel, UserModel, UserModel, number> implements BeanFactory {
    @Resource()
    userService: UserService;

    getService(): UserService {
        return this.userService;
    }

    getFormValidate(): Array<Function | UserModel> {
        return [UserModel];
    }

    /**
     * 登录
     * @param login_name 登录名
     * @param password 密码
     */
    @PostMapping("login")
    login(userModel: UserModel): AxiosPromise<Result<UserModel>> {
        return this.getService().login(this.request(userModel));
    }

    /**
     * 退出登录
     */
    @PostMapping("loginOut")
    loginOut() {
        return this.getService().loginOut(super.request());
    }

}
